/*
 * File     : PaddingParameter.java
 * Created  : 11 Nov 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.internal.call;

import static org.objectweb.asm.Opcodes.ICONST_0;
import static org.objectweb.asm.Opcodes.LCONST_0;

import org.objectweb.asm.MethodVisitor;

/**
 * Special parameter that is padding to displace other parameters to fix in
 * certain registers or on the stack in a certain alignment.
 *
 * @author Matthew Wilson
 */
final class PaddingParameter extends Parameter
{

    /**
     * @param nativeType
     *            the native type of the parameter
     */
    public PaddingParameter( final char nativeType )
    {
        setNativeType( nativeType );
        setJavaIndex( -1 );
    }

    @Override
    int getJavaVarSlots()
    {
        return 0;
    }

    @Override
    void writeGetParameter( final MethodVisitor methodVisitor )
    {
        switch ( getNativeType() )
        {
            case 'I':
                methodVisitor.visitInsn( ICONST_0 );
                break;

            case 'J':
                methodVisitor.visitInsn( LCONST_0 );
                break;

            default:
                throw new AssertionError( getNativeType() );
        }
    }

    @Override
    void writeReturnParameter( final MethodVisitor methodVisitor, final int returnVarIndex )
    {
        throw new UnsupportedOperationException();
    }

    /** {@inheritDoc} */
    @Override
    public String toString()
    {
        return "[padding]";
    }

}
